package com.hdu.hot100.trick;

public class lc75 {
    class Solution {
        public void sortColors(int[] nums)
        {
             int left = 0, cur = 0, right = nums.length - 1;
            while (cur <= right)
            {
                if (nums[cur] == 0)
                {
                    swap(nums, left, cur);
                    left++;
                    cur++;
                }
                else if (nums[cur] == 1)
                {
                    cur++;
                }
                else
                {
                    swap(nums, cur, right);
                    right--;
                }
            }
        }

        void swap(int[] nums, int l, int r)
        {
            int tmp = nums[l];
            nums[l] = nums[r];
            nums[r] = tmp;
        }
    }
}
